/**
 * SKINNED MESH & ANIMATIONS.
 */
package  
{
	import flare.basic.*;
	import flare.core.*;
	import flare.loaders.collada.*;
	import flare.system.*;
	import flare.utils.*;
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	
	[SWF(frameRate = 120, backgroundColor = 0x808080, width = 800, height = 600 )]
	/**
	 * ...
	 * @author Ariel Nehamd
	 */
	public class Test06_Skin extends Sprite
	{
		private var scene:Scene3D;		
		private var model:Pivot3D;
		private var model2:Pivot3D;
		private var clone:Pivot3D;
		private var skin:Pivot3D;
		
		public function Test06_Skin() 
		{
			ColladaLoader.texturesFolder = "textures";
			
			stage.align = StageAlign.TOP_LEFT;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			scene = new Viewer3D( this );
			scene.addEventListener( Scene3D.COMPLETE_EVENT, completeEvent );
			
			model = scene.addChildFromFile( "player.f3d" );
			model.setScale( 50, 50, 50 );
			
			// camera posiion and orientation.
			scene.camera.setPosition( 0, 100, -100 );
			scene.camera.lookAt( 0, 50, 0 );
			scene.camera.far = 100000;
			
			// light parameters.
			scene.ambientColor = new Vector3D( 0.2, 0.2, 0.2 );  // <-- RGB ambient light color.
			scene.defaultLight.color = new Vector3D( 1, 1, 1, 1 ); // <-- RGB light colors and contrast.
			scene.defaultLight.setRotation( 40, 40, 0 );		
		}
		
		private function completeEvent(e:Event):void 
		{
			model.play();
			
			scene.addEventListener( Scene3D.UPDATE_EVENT, updateEvent );
		}
		
		private function updateEvent(e:Event):void 
		{
			// play and stop the animation.
			if ( Input3D.keyHit( Input3D.P ) ) model.play()
			if ( Input3D.keyHit( Input3D.S ) ) model.stop()
			
			// inverse the frameSpeed.
			if ( Input3D.keyHit( Input3D.F ) ) model.frameSpeed = -model.frameSpeed
			
			// increment and decrement the speed of animation.
			if ( Input3D.keyHit( Input3D.Z ) ) model.frameSpeed -= 0.1
			if ( Input3D.keyHit( Input3D.X ) ) model.frameSpeed += 0.1			
			if ( Input3D.keyHit( Input3D.R ) ) model.frameSpeed = 1
		}		
	}
}